package com.heima.media.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.heima.common.dto.ResponseResult;
import com.heima.media.entily.WmUser;
import com.heima.media.mapper.WmUserMapper;
import com.heima.media.service.IWmUserService;

import org.springframework.stereotype.Service;

import java.util.Date;


/**
 * <p>
 * 自媒体用户信息表 服务实现类
 * </p>
 * @since 2022-06-26
 */
@Service
public class WmUserServiceImpl extends ServiceImpl<WmUserMapper, WmUser> implements IWmUserService {
    @Override
    public ResponseResult<WmUser> saveWmUser(WmUser user) {
        LambdaQueryWrapper<WmUser> query = new LambdaQueryWrapper<>();
        query.eq(WmUser::getApUserId, user.getApUserId());
        //先进行查询
        WmUser one = this.getOne(query);
        // 判断用户是否存在
        if(one==null){
            user.setCreatedTime(new Date());
          //  返回自增主键id
            this.baseMapper.insert(user);
        }
        return ResponseResult.okResult(user);
    }
    }

